<!--
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
-->

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'list_task.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <!--	<%@include file="../../script.html" %>-->
    <link th:insert="~{views/script :: tiancai}"/>
</head>

<body>
<div>
    <span>客户视图：</span><span onclick="return whole('/manage/task/TaskAction_findByPage.action')"
                            class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">全部</span>|
    <span onclick="return myTask('/manage/task/TaskAction_myTask.action')" class="easyui-linkbutton"
          data-options="plain:true">我的任务</span>|
    <span onclick="return myDistributeTask('/manage/task/TaskAction_myDistributeTask.action')" class="easyui-linkbutton"
          data-options="plain:true">我分配的任务</span>
    &nbsp;&nbsp;&nbsp;
    <span onclick="return notInitiated('/manage/task/TaskAction_notInitiated.action')" class="easyui-linkbutton"
          data-options="iconCls:'icon-ok',plain:true">未启动</span>|
    <span onclick="return putOff('/manage/task/TaskAction_putOff.action')" class="easyui-linkbutton"
          data-options="plain:true">推迟</span>|
    <span onclick="return inProcess('/manage/task/TaskAction_inProcess.action')" class="easyui-linkbutton"
          data-options="plain:true">进行中</span>|
    <span onclick="return completed('/manage/task/TaskAction_completed.action')" class="easyui-linkbutton"
          data-options="plain:true">已完成</span>|
    <span onclick="return closed('/manage/task/TaskAction_closed.action')" class="easyui-linkbutton"
          data-options="plain:true">关闭的</span>|
    <span onclick="return endToday('/manage/task/TaskAction_endToday.action')" class="easyui-linkbutton"
          data-options="iconCls:'icon-ok',plain:true">今日截止</span>|
    <span onclick="return endWeek('/manage/task/TaskAction_endWeek.action')" class="easyui-linkbutton"
          data-options="plain:true">本周截止</span>|
    <span onclick="return endMonth('/manage/task/TaskAction_endMonth.action')" class="easyui-linkbutton"
          data-options="plain:true">本月截止</span>|
    <span onclick="return recentlyAssigned('/manage/task/TaskAction_recentlyAssigned.action')" class="easyui-linkbutton"
          data-options="plain:true">最近分配</span>|
    <span onclick="return recentlyUpdated('/manage/task/TaskAction_recentlyUpdated.action')" class="easyui-linkbutton"
          data-options="plain:true">最近更新</span>|
    &nbsp;&nbsp;&nbsp;
    <span id="recycleBin" class="easyui-linkbutton" data-options="iconCls:'icon-recover_deleted',plain:true">回收站</span>
    &nbsp;
</div>
<div>
    <select name="task" class="easyui-combobox theme-textbox-radius" style="width:120px">
        <option value="1">任意字段</option>
        <option value="subject">主题</option>
        <option value="creatorUsername">创建者</option>
        <option value="ownerUsername">负责人</option>
        <option value="status">任务状态</option>
        <option value="priority">优先级</option>
        <option value="description">描述</option>
        <option value="dueDate">截止日期</option>
        <option value="createDate">创建日期</option>
        <option value="updateDate">更行日期</option>
    </select>
    <select name="taskVo.creatorUsername" class="easyui-combobox theme-textbox-radius" style="width:100px">
        <option value="1">包含</option>
        <option value="2" selected>人名</option>  <!--{taskVo.ownerUsername? "selected":""-->
    </select>
    <input name="subject" type="text" class="easyui-textbox theme-textbox-radius">
   <!-- <a href="javascript:void(0);" onclick="return searchs('/manage/task/TaskAction_search.action')" class="easyui-linkbutton"
       data-options="iconCls:'icon-search'">搜索</a>-->
    <span onclick="return searchs('/manage/task/TaskAction_recentlyUpdated.action')" class="easyui-linkbutton"
          data-options="plain:true">搜索</span>
</div>

<table id="taskList" class="easyui-datagrid">

</table>

<div id="toolbar">
    <a href="javascript:void(0);" onclick="return add('manage/task/TaskAction_edit.action')" class="easyui-linkbutton"
       data-options="iconCls:'icon-add',plain:true">新建</a>
    <a href="javascript:void(0);" onclick="return del('/manage/task/TaskAction_del.action')" class="easyui-linkbutton"
       data-options="iconCls:'icon-remove',plain:true">删除</a>
    <a href="javascript:void(0);" onclick="return edit('manage/task/TaskAction_modify.action');" id="editBtn"
       class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>

</div>

</body>
<script type="text/javascript" th:inline="none">
    function add(url) {
        parent.openTopWindow(
            {
                width: 500,
                height: 700,
                "title": "修改任务",
                "url": url,
                close: function () {
                    $("#taskList").datagrid("reload")
                }

            }
        )
    }

    function searchs(url) {
        // debugger
        var field = $("input[name=subject]").val()
        $("#taskList").datagrid("load", {
            "url" : url + "?field=" + field
        })
    }

    function del(url) {
        var rows = $("#taskList").datagrid("getChecked");
        if (!rows.length) {
            $.messager.alert("警告", "请选择要删出的任务");
            return;
        }
        $.messager.confirm("警告", "数据删除无法恢复", function (b) {
            if (b) {
                var ids = new Array();
                $.each(rows, function (index, obj) {
                    ids.push(obj.id)
                })
                ids = ids.join(",")
                $.post(url,
                    {"ids": ids},
                    function (data) {
                        if (data.success && data) {
                            $.messager.alert("提示", data.message)
                            $("#taskList").datagrid("reload");
                            return
                        }
                        $.messager.alert("提示", data.message)

                    },
                    "json"
                )
            }
        })

    }

    function edit(url) {
        var rows = $("#taskList").datagrid("getChecked");
        if (!rows.length) {
            $.messager.alert("提示", "请选择要修改的任务");
            return;
        }
        var taskId = rows[0].id;
        parent.openTopWindow({
            width: 500,
            height: 700,
            title: "修改任务",
            "url": url + "?id=" + taskId,
            close: function () {
                $("#taskList").datagrid("reload")
            }
        })
    }

    $(function () {
        $("#taskList").datagrid({
            url: "/manage/task/TaskAction_findByPage.action",
            pagination: true,
            toolbar: "#toolbar",
            fitColumns: true,
            idField: "task.id",
            rownumbers: true,
            columns: [[
                {field: "id", title: "选择", checkbox: true},
                {field: "subject", title: "主题", width: 10},
                {field: "aboutUsers", title: "相关信息", width: 10},
                {field: "ownerUserId", title: "负责人", width: 15},
                {field: "status", title: "状态", width: 10},
                {field: "priority", title: "优先级", width: 15},
                {field: "creatorUserId", title: "创建者", width: 15},
                {field: "dueDate", title: "截止日期", width: 15},
                {
                    field: "operation", title: "操作", formatter: function (value, rowData, index) {
                        return "<a href='javascript:void(0);' onclick='see(" + index + ")'>查看</a>" +
                            "<a href='javascript:void(0);' onclick='modify(" + index + ")'>修改</a>"
                    }
                },


            ]],

            loadFilter: function (data) {
                return {"total": data.data.totalRows, "rows": data.data.result}
            }

        })
    })

    function see(index) {
        $("#taskList").datagrid("selectRow", index);
        var row = $("#taskList").datagrid("getSelected");
        console.log('row---', row);
        var id = row.id;
        parent.openTopWindow({
            width: 500,
            height: 700,
            title: "查看",
            url: "/manage/task/TaskAction_see.action?id=" + id,
            close: function () {
                $("#taskList").datagrid("reload")
            }
        })

    }

    function modify(index) {
        $("#taskList").datagrid("selectRow", index)
        var row = $("#taskList").datagrid("getSelected")
        var id = row.id;
        parent.openTopWindow(
            {
                width: 500,
                height: 700,
                title: "修改任务",
                url: "/manage/task/TaskAction_modify.action" + "?id=" + id,
                close: function () {
                    $("#taskList").datagrid("reload")
                }
            }
        )
    }

    //查询全部任务
    function whole(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }
    //我的任务
    function myTask(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

    //查询我分配的任务
    function myDistributeTask(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

    //未启动
    function notInitiated(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

    //推迟
    function putOff(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

    //进行中
    function inProcess(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }
    //已完成
    function completed(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }
    //关闭的
    function closed(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

    //今日截止
    function endToday(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }


    //本周截止
    function endWeek(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }


    //本月截止
    function endMonth(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }


    //最近分配
    function recentlyAssigned(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }


    //最近更新
    function recentlyUpdated(url) {
        $("#taskList").datagrid({
            "url": url
        })
    }

</script>
</html>
